package com.pjs.tdd;

import java.math.BigDecimal;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public class Money {
	
	private final BigDecimal amount;
	private final Currency currency;
	
	public static Money money(double amount,final Currency currency){
		return new Money(amount,currency);
	}
	
	public Money(double amount, final Currency currency) {
		super();
		this.amount = new BigDecimal(amount);
		this.currency = currency;
	}
	
	public double amount(){
		return this.amount.doubleValue();
	}
	
	public Currency currency(){
		return this.currency;
	}
	
	public int hashCode() {
		return new HashCodeBuilder(17, 37).
					append(amount).
						append(currency).
							toHashCode();
	}	
	
	@Override 
	public boolean equals(Object obj) {
		Money rhs = (Money) obj;
		boolean equals= new EqualsBuilder().
					append(amount,rhs.amount).
						append(currency,rhs.currency).
							isEquals();
		return equals;
	}
	
}
